package com.sdtbu.ylgh.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdtbu.ylgh.dao.DepartmentDao;
import com.sdtbu.ylgh.dao.GhRosterDao;
import com.sdtbu.ylgh.entity.DepartmentEntity;
import com.sdtbu.ylgh.entity.DoctorsEntity;
import com.sdtbu.ylgh.entity.GhRosterEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.sdtbu.ylgh.dao.GhOrderDao;
import com.sdtbu.ylgh.entity.GhOrderEntity;
import com.sdtbu.ylgh.service.GhOrderService;


@Service("ghOrderService")
public class GhOrderServiceImpl extends ServiceImpl<GhOrderDao, GhOrderEntity> implements GhOrderService {

    @Autowired
    GhRosterDao ghRosterDao;
    @Autowired
    GhOrderDao ghOrderDao;

    /**
     * 添加一个挂号信息，并且医生排班表的 已预约人数 加一
     * @param ghOrder
     * @return
     */
    @Override
    public boolean saveInfo(GhOrderEntity ghOrder) {
        ghOrder.setOrderStatus(0);
        boolean b = save(ghOrder);
        if (b){
            GhRosterEntity ghRoster = new GhRosterEntity();
            ghRoster.setId(ghOrder.getRosterId());
            ghRoster.setReserveNum(ghOrder.getNumber());
            ghRosterDao.updateById(ghRoster);
        }

        return b;
    }

    /**
     *  查询 用户自己的挂号信息，根据就诊人 id ，时间
     * @param
     * @return
     */
    @Override
    public List<Map<String, Object>> listToNew(Map<String, Object> map) {
        List<Map<String, Object>> mapList = ghOrderDao.userList(map.get("user_id"), map.get("patient_id"));
        return mapList;
    }
}